package com.bingqing.controller;

import com.bingqing.common.AutoLog;
import com.bingqing.common.Result;
import com.bingqing.entity.Admin;
import com.bingqing.entity.Audit;
import com.bingqing.entity.Book;
import com.bingqing.entity.Params;
import com.bingqing.service.AuditService;
import com.bingqing.service.BookService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ClassName: AdminController
 * Package: com.bingqing.springboot.controller
 * Description:
 *
 * @Author liuyujie
 * @Create 2024-03-06 13:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/audit")
@CrossOrigin //解决跨域问题
public class AuditController {
    @Resource
    private AuditService auditService;

    //分页查询
    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Audit> info = auditService.findBySearch(params);
        return Result.success(info);
    }
    //保存
    @PostMapping("/save")
    public Result save(@RequestBody Audit audit){
        if(audit.getId() == null){
            auditService.add(audit);
        }else {
            auditService.update(audit);
        }
        return Result.success();
    }
    @PostMapping("/add")
    @AutoLog("新增请假")
    public Result add(@RequestBody Audit audit){
        auditService.add(audit);
        return Result.success();
    }
    @PostMapping("/edit")
    @AutoLog("编辑请假")
    public Result edit(@RequestBody Audit audit){
        auditService.update(audit);
        return Result.success();
    }

    //删除
    @DeleteMapping("/{id}")
    @AutoLog("删除请假")
    public Result delete(@PathVariable Integer id){
        auditService.deleteById(id);
        return Result.success();
    }
}
